<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/icon.css" />
<script type="text/javascript" src="<?=base_url()?>file/js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>file/js/easyui/jquery.easyui.min.js"></script>
<!--<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyC0JhNTyjMpdmUPMDYWIVuE57dUIHZH1SU&sensor=true"></script>-->
<script type="text/javascript" src="<?=$api?>"></script>



<script type="text/javascript" src="<?=base_url()?>file/js/map/epoly.js"></script>
    <script type="text/javascript">
    var polygon;
    function initialize() {
     
        var map = new GMap2(document.getElementById("map_canvas"))
        map.setCenter(new GLatLng(-1.9112665350965847,117.7294921875), 5);

        GEvent.addListener(map, "click", function(overlay,point){
            document.getElementById("latlng").value = point;
        });
                           
        <?php
        if($hasil != null) {
            $ter = $this->mgis->getTerritoryMember($this->input->post("territory"));
                    
            if($ter != null) {
                $i = 0;

                foreach($ter as $r) {
                    $this->mgis->pathTer = "";
                    $hal = $this->mgis->getBoundaryTerritory($r);
                    $bound = "";
                    $x = 0;
                    if($hal != null) {
                        foreach($hal as $v) {
                            if($x <> 0) {
                                $bound .= ",";
                            }                       
                            $bound .= "new GLatLng(".$v->lat.",".$v->lon.")";

                            $x++;
                        }   
                    }
                }
            }
                  
        ?>
        var bound = [<?= $bound ?>,];
        polygon = new GPolygon(bound,5, 1,0.2);
        map.addOverlay(polygon);

        if(polygon.Contains(new GLatLng<?= $this->input->post("latlng") ?>)) {
            alert("Contains");
        }else {
            alert("Not contain")
        }
        <?php
        }
        ?>

      
    }

    </script> 
    
<script>

$("#li").hide();    

</script>
    
<div class="box">
     <!-- box / title -->
        <div class="title">
                <h5>Check Position</h5>                
        </div>
     <form id="form" action="<?=$_SERVER['PHP_SELF']?>" method="post">
                <div class="form">
                        <div class="fields">
                                <div class="field">
                                        <div class="label">
                                                <label for="user">Latitude,Longitude:</label>
                                        </div>
                                        <div class="input">
                                                <input name="latlng" id="latlng" value="<?= $this->input->post('latlng') ? $this->input->post('latlng') : "" ?>" required="true" style="width:200px;">                                                
                                                Click Pada peta untuk mendapatkan posisi
                                        </div>
                                </div>                                  
                                <div class="field">
                                        <div class="label">
                                                <label for="user">Territory:</label>
                                        </div>
                                        <div class="input">
                                                <input id="cc" name="territory" class="easyui-combotree" url="<?= base_url()?>index.php/gis/territory_json" value="<?= $this->input->post('territory') ? $this->input->post('territory') : 1 ?>" required="true" style="width:200px;">                                                
                                        </div>
                                </div>  
                            <div class="buttons">
                                        <input type="submit" name="submit" value="Check" />                                     
                                </div>                            
                        </div>
                </div>
     </form>
         <div id="map_canvas" style="width: 100%; height: 400px"></div> 
         <script type="text/javascript">
                initialize();
         </script>
</div>